// 该文件就是和学生模块的请求相关的 api
import request from "./request";
import { IStu, INewStu } from "../types";

export function getStuListApi(): IStu[] {
  const resp = request("/api/stu", {
    method: "GET",
  }) as unknown;
  return resp as IStu[];
}

// 根据 id 获取学生详情
export function getStuByIdApi(id: string): IStu {
  const resp = request(`/api/stu/${id}`, {
    method: "GET",
  }) as unknown;
  return resp as IStu;
}

// 根据 id 删除学生
export function deleteStuByIdApi(id: string) {
  return request({
    url: `/api/stu/${id}`,
    method: "DELETE",
  });
}

// 添加学生
export function addStuApi(data: INewStu) {
  return request({
    url: "/api/stu",
    method: "POST",
    data,
  });
}

// 编辑学生
export function editStuByIdApi(id: string, data: Partial<INewStu>) {
  return request({
    url: `/api/stu/${id}`,
    method: "PATCH",
    data,
  });
}
